package com.itheima.controller;

import com.itheima.common.PaginationVO;
import com.itheima.common.Result;
import com.itheima.entity.YddTag;
import com.itheima.service.AdvposService;
import com.itheima.vo.advVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * advpos控制器
 *
 * @author 13225
 * @date 2023/09/23
 */
@Slf4j
@RestController
@RequestMapping("/ydd_advpos")
@RequiredArgsConstructor
public class AdvposController {
    private final AdvposService advposService;

    /**
     * 页
     *
     * @param advposdesc advposdesc
     * @param advposname advposname
     * @param page       页
     * @param limit      限度
     * @return {@link Result}<{@link PaginationVO}<{@link advVO}>>
     */
    @GetMapping("/list")
    public Result<PaginationVO<advVO>> page(String advposdesc, String advposname,
                                            @RequestParam(defaultValue = "1") String page,
                                            @RequestParam(defaultValue = "10") String limit) {
        //记录日志
        log.info("分页查询，参数：{},{},{},{}", page, limit, advposdesc,advposname);
        //调用业务层分页查询功能
        PaginationVO<advVO> pages = advposService.page(page, limit, advposdesc,advposname);
        //响应
        return Result.success(pages);
    }

    /**
     * 获取所有列表
     *
     * @return {@link Result}<{@link List}<{@link advVO}>>
     */
    @GetMapping("/all")
    public Result<List<advVO>> getAllList() {
        List<advVO> advVOList = advposService.getAllList();
        return Result.success(advVOList);
    }

    /**
     * 添加advpos
     *
     * @param adv 副词。
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/add")
    public Result<?> addAdvpos(@RequestBody advVO adv) {
        advposService.addAdvpos(adv);
        return Result.success();
    }

    /**
     * 更新advpos
     *
     * @param adv 副词。
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/update")
    public Result<?> updateAdvpos(@RequestBody advVO adv) {
        advposService.updateAdvpos(adv);
        return Result.success();
    }

    /**
     * 行信息advpos
     *
     * @param id id
     * @return {@link Result}<{@link advVO}>
     */
    @GetMapping("/rowInfo")
    public Result<advVO> rowInfoAdvpos(Integer id) {
        advVO adv = advposService.rowInfoAdvpos(id);
        return Result.success(adv);
    }

    @GetMapping("/del")
    public Result<?> deleteAdvpos(Integer id) {
         advposService.deleteAdvpos(id);
        return Result.success();
    }
}
